<?php
namespace app\yticnus\Controller;
class Message extends Common {

	/*
	*	构造函数
	*/
	function __construct(){
		parent::__construct();
    }
    
	/*
	*	添加消息界面
    */
    public function add(){
		if(request()->isPost()){
			$content   = input("content");
			if(!$content) $this->error('消息内容为空');
			$data['content'] = $content;
            $data['time'] = time();
            $id = input('id');
			if($id){
				db('message')->where("id='$id'")->update($data);
			}else {
				db('message')->insert($data);
			}
			$this->success("操作成功!",url('message/index'));
		}
		return $this->fetch();
    }

 	/*
	*	消息列表界面
    */
    public function index(){
        $list = db('message')->order('time desc')->paginate(10);
        $this->assign('data',$list);
        return $this->fetch();
    }

 	/*
	*	删除消息
    */
    public function del(){
        $id = input('id');
        $data = db('message')->where('id',$id)->find();
        if($data){
            db('message')->where('id',$id)->delete();
        }else{
            $this->error('要删除的消息不存在');
        }
        $this->success('操作成功',url('message/index'));
    }
}